using System;
using System.IO;
using System.Linq;

namespace ImageProcessing.Storage
{
    public class OnlinePersistanceDB : PersistanceDB
    {
        private const string DbFileFolder = "Database";

        private readonly string _fullDbPath;

        public OnlinePersistanceDB()
        {
            _fullDbPath = OnlineHelpers.GetDBPath(DbFileFolder);
        }

        protected override Stream FileStream(string fileName, FileMode fileMode, FileAccess fileAccess)
        {
            return File.Open(Path.Combine(_fullDbPath, fileName), fileMode, fileAccess);
        }

        public override string[] GetAllPointsFiles()
        {
            DirectoryInfo directoryInfo = new DirectoryInfo(_fullDbPath);
            var files = directoryInfo.GetFiles("*" + PointsFileExtension);
            return files.Select(x => x.Name).ToArray();
        }

        protected override void DeleteFile(string fileName)
        {
            File.Delete(Path.Combine(_fullDbPath, fileName));
        }
    }
}